#include "authorizationexecutor.h"

AuthorizationExecutor::AuthorizationExecutor()
{

}

AuthorizationExecutor::AuthorizationExecutor(Session* s)
{
    session = s;
}

void AuthorizationExecutor::execute(Para* cmd)
{
    QBool flag = QBool(false);
    foreach (Para p, cmd->getArgs())
    {
        if (p.getName() == "success")
        {
            if (p.getText() == "TRUE")
                flag=QBool(true);
            else
                flag = QBool(false);
            break;
        }
    }
    foreach (Para p, cmd->getArgs())
    {
        if (flag){
            if (p.getName() == "identify")
            {
                session->setId(p.getText());
                emit proceed();
                break;
            }
        }else{
            if (p.getName() == "reason")
            {
                emit fail(p.getText());
                break;
            }
        }
    }
}
